package TreeDayShuZu;

import org.junit.Test;

import java.beans.Transient;

public class Dome05 {
    public static void main(String[] args) {
        //数组的反转()方法一
        int[] arr = {1, 2, 3, 4, 5};
        System.out.println("反转之前的数组");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        for (int i = 0; i < arr.length / 2; i++) {
            int temp = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
        }
        System.out.println("\n反转之后的数组");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    //方法二
    @Test
    public void test01() {
        int[] arr = {6, 7, 8, 9, 10};
        System.out.println("反转之前的数组");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        for (int left = 0, right = arr.length - 1; left < right; left++, right--) {
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }
        System.out.println("\n反转之后的数组");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
